package com.security.common.code.image;

import com.security.common.code.AbstractValidateCodeProcessor;
import com.security.common.code.sms.ValidateCode;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

import javax.imageio.ImageIO;
import java.io.IOException;

/**
 * @Author: TongRui乀
 * @Date: 2020/3/21 17:55
 * @description：
 */
@Component
public class ImageValidateCodeProcessor extends AbstractValidateCodeProcessor<ImageCode> {
    @Override
    protected void send(ValidateCode validateCode, ServletWebRequest request) {
        try {
            ImageIO.write(((ImageCode)validateCode).getImage(),"JPEG", request.getResponse().getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
